/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tictactoe;

import figure.Cross;
import figure.Round;
import java.awt.Color;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
 

/**
 *
 * @author User
 */
public class SmallField extends JPanel  {
  private int row;
  private int col;
  private boolean figure = true;
  private boolean step = false;
  
  
  public SmallField(int row, int col, boolean figure, boolean step)
  {
    this.figure = figure;
    this.step = step;
    this.setSize(100, 100);
    this.setBorder(BorderFactory.createLineBorder(Color.BLACK,1));
    this.setVisible(true);
    this.setBackground(Color.white);
    this.addMouseListener(new NodeMouseListener(this));
    this.row = row;
    this.col = col;
  //  this.add(new Cross());
  }
  
  public void setFigure(boolean figure)
  {
    this.figure = figure;
  }
  
  public void setStep(boolean step)
  {
    this.step = step;
  }
  
  public boolean getStep()
  {
    return step;
  }
  
      class NodeMouseListener extends MouseAdapter {
        JPanel panel;
        
        public NodeMouseListener(JPanel panel)
        {
          this.panel = panel;
        }
        
        public void mousePressed(MouseEvent event) {
          if (step)
          {
            System.out.println(row + " " + col);
            if (figure) {
              panel.add(new Cross());
            } else {
              panel.add(new Round());
            }

            panel.repaint();
            UserComman.step(row, col);
          }
        }
    }
  
}
